<?php

# !almost! disposed

# http://projects:8081/cdapp-2kt-api/api/hours_personal_report_get.php

include_once './_portal.php';

const PARAM_NAME_USERS = 'ATCOSUsers';
const PARAM_NAME_USERS_GROUPED = 'ATCOSUsersGrouped';

$start = isset($_GET['start']) ? $_GET['start'] : date('Y-m-d');
$end = isset($_GET['end']) ? $_GET['end'] : date('Y-m-d');
$full = isset($_GET['full']) ? $_GET['full'] : 0;
$lite = isset($_GET['lite']) ? $_GET['lite'] : 0;
$finished = isset($_GET['finished']) ? $_GET['finished'] : 1;

$columns = $full == 1 ? '`mix`, `number`, `month`, `name`, `rank`, `qualify`, `license`, `seat`, `sector`, `post`, `role`, `begin`, `end`, `minutesDaytime`, `minutesEvening`, `minutesNight`, `minutes`, `hours`, `hoursRaw`, `wage`, `salary`, `ratio`' : ($lite == 1 ? '`name`, `seat`, `post`, `role`, `begin`, `end`,   `hours`' : '`number`, `month`, `name`, `rank`, `qualify`, `license`, `seat`, `sector`, `post`, `role`, `begin`, `end`,  `minutes`, `hours`, `hoursRaw`, `wage`, `salary`, `ratio`');

// $sql = "SELECT {$columns} FROM `2kt_hours_report` WHERE (`begin` >= '{$start}' AND `end` <= '{$end}') OR (`begin` < '{$start}' AND `end` > '{$start}') OR (`begin` < '{$end}' AND `end` > '{$end}')";

$sql = "SELECT {$columns} FROM `2kt_hours_report` WHERE `begin` <= '{$end}' AND `end` >= '{$start}'";

$data = exec_sql($sql);
$users = get_param(PARAM_NAME_USERS);
$users_grouped = get_param(PARAM_NAME_USERS_GROUPED);

output([
  'start' => $start, // added in workingdays summary
  'end' => $end, // added in workingdays summary
  'count' => is_array($data) ? count($data) : -1,
  'data' => $data,
  'users' => $users, // added in workingdays summary
  'usersGrouped' => $users_grouped, // added in workingdays summary
]);
